package com.dream.myqiyi;

import com.dream.myqiyi.R;
import com.dream.myqiyi.ui.NoteListActivity;
import com.dream.myqiyi.ui.Welcome;

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Gravity;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;

public class Appstart extends Activity {

	private static final int DIALOG_CONN_SERVER = 3;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);	
		setContentView(R.layout.appstart);
		//requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
		//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        //        WindowManager.LayoutParams.FLAG_FULLSCREEN);   //全屏显示
		//Toast.makeText(getApplicationContext(), "孩子！好好背诵！", Toast.LENGTH_LONG).show();
		//overridePendingTransition(R.anim.hyperspace_in, R.anim.hyperspace_out);
		
		new InitTask().execute("");
		
	}
	
	@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case DIALOG_CONN_SERVER: {
			ProgressDialog dialog = new ProgressDialog(this);
			dialog.setMessage("正在连接服务器...请稍候");
			dialog.setIndeterminate(true);
			dialog.setCancelable(true);
			dialog.getWindow().setGravity(Gravity.BOTTOM); 
			return dialog;
		}
		}
		return null;
	}

	private class InitTask extends AsyncTask<String, String, String> {
		private boolean isInitSuccess = false;
		public String doInBackground(String... params) {
			isInitSuccess = BaseApp.init();
			return "";
		}

		@Override
		protected void onPreExecute() {
			isInitSuccess = false;
			showDialog(DIALOG_CONN_SERVER);
		}

		@Override
		public void onPostExecute(String Re) {
			//绑定LISTVIEW
			removeDialog(DIALOG_CONN_SERVER);
			if (isInitSuccess) {
				Intent intent = new Intent (Appstart.this, NoteListActivity.class);			
				startActivity(intent);			
				Appstart.this.finish();
			} else {
				
			}
		}
	}
}